import Index from '../components/main.vue'

const Main = () => import('@/components/main.vue');
const login = () => import('@/components/login/index.vue');
const home = () => import('@/components/home/index.vue');
const page404 = () => import('@/components/common/404.vue');
const page500 = () => import('@/components/common/500.vue');
const hello = () => import('@/components/HelloWorld.vue');
const About = () => import('@/components/about/index.vue');
const Teams = () => import('@/components/teams/index.vue');
const Honor = () => import('@/components/honor/index.vue');
const Teachers = () => import('@/components/teachers/index.vue');
const TeachActivity = () => import('@/components/teach-activity/index.vue');
const UnionActivity = () => import('@/components/union-activity/index.vue');
const StudentActivity = () => import('@/components/student-activity/index.vue');
const Craftsmanship = () => import('@/components/craftsmanship/index.vue');
const Flower = () => import('@/components/flower/index.vue');
const Notice = () => import('@/components/notice/index.vue');
const News = () => import('@/components/news/index.vue');
const CookBook = () => import('@/components/cookbook/index.vue');
const Live = () => import('@/components/live/index.vue');
const MailBox = () => import('@/components/mailbox/index.vue');
import Vue from 'vue';
import {SERVICE_URLS} from "../libs/service.url";


export const loginRouter = {
  path: '/login',
  name: 'login',
  meta: {
    title: 'Login - 登录'
  },
  component: login,
  beforeEnter: (to, from, next) => {
    let self = this;
    Vue.submit(self, {
      loading: 'loading',
      url: SERVICE_URLS.common.exit,
      params: {},
      callback: (_data) => {
        localStorage.clear();
        next(true);
      }
    });
  }
};


// 作为Main组件的子页面展示但是不在左侧菜单显示的路由写在otherRouter里
export const otherRouter = {
  path: '/otherRouter',
  name: 'otherRouter',
  component: Main,
  children: [
    {
      path: '',
      redirect: 'home'
    },
    {
      path: 'home',
      title: '首页',
      name: 'home_index',
      component: hello
    }
  ]
};


export const appRouter = [
  {
    path: '/culture',
    icon: 'gear-b',
    title: '百年晋小',
    component: Index,
    children: [
      {
        path: '',
        redirect: 'about'
      },
      {
        path: 'about',
        name: 'about',
        title: '关于晋阳',
        component: About
      },
      {
        path: 'teams',
        name: 'teams',
        title: '和谐团队',
        component: Teams
      },
      {
        path: 'honor',
        name: 'honor',
        title: '荣誉展示',
        component: Honor
      }
    ]
  },
  {
    path: '/teachers',
    icon: 'gear-b',
    title: '师资力量',
    component: Index,
    children: [
      {
        path: '',
        redirect: 'detail'
      },
      {
        path: 'detail',
        name: 'detail',
        title: '老师风采',
        component: Teachers
      },
      {
        path: 'teach-activity',
        name: 'teach-activity',
        title: '教研活动',
        component: TeachActivity
      },
      {
        path: 'union-activity',
        name: 'union-activity',
        title: '工会活动',
        component: UnionActivity
      }
    ]
  },
  {
    path: '/student',
    icon: 'gear-b',
    title: '向阳花们',
    component: Index,
    children: [
      {
        path: '',
        redirect: 'activity'
      },
      {
        path: 'activity',
        name: 'activity',
        title: '学生活动',
        component: StudentActivity
      },
      {
        path: 'craftsmanship',
        name: 'craftsmanship',
        title: '童心飞扬',
        component: Craftsmanship
      },
      {
        path: 'flower',
        name: 'flower',
        title: '荣誉之花',
        component: Flower
      }
    ]
  },
  {
    path: '/campus',
    icon: 'gear-b',
    title: '校园新闻',
    component: Index,
    children: [
      {
        path: '',
        redirect: 'notice'
      },
      {
        path: 'notice',
        name: 'notice',
        title: '校园公告',
        component: Notice
      },
      {
        path: 'news',
        name: 'news',
        title: '校园新闻',
        component: News
      },
      {
        path: 'cookbook',
        name: 'cookbook',
        title: '每周食谱',
        component: CookBook
      },
    ]
  },
  {
    path: '/live',
    icon: 'gear-b',
    title: '直播管理',
    component: Index,
    children: [
      {
        path: '',
        redirect: 'index'
      },
      {
        path: 'index',
        name: 'index',
        title: '在线直播',
        component: Live
      }
    ]
  },
  {
    path: '/mailbox',
    icon: 'gear-b',
    title: '校长信箱',
    component: Index,
    children: [
      {
        path: '',
        redirect: 'words'
      },
      {
        path: 'words',
        name: 'words',
        title: '留言管理',
        component: MailBox
      }
    ]
  }
];


export const routers = [
  {
    path: '',
    redirect: '/login',
  },

  loginRouter,
  ...appRouter
];

